import 'package:flutter/material.dart';
import 'package:flutter_cost/module/equity/view.dart';
import 'package:flutter_cost/module/home/view.dart';
import 'package:get/get.dart';

import 'logic.dart';

class MainPage extends StatelessWidget {
  final logic = Get.find<MainLogic>();
  final state = Get.find<MainLogic>().state;

  final List<Widget> pages = [HomePage(), EquityPage(), HomePage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        physics: const ClampingScrollPhysics(),
        controller: logic.pageController,
        onPageChanged: (int index) {
          state.currentIndex.value = index;
        },
        children: pages,
      ),
      bottomNavigationBar: Obx(
        () => BottomNavigationBar(
          currentIndex: state.currentIndex.value,
          onTap: (int index) {
            logic.pageController.animateToPage(
              index,
              duration: const Duration(milliseconds: 400),
              curve: Curves.easeInOutQuart,
            );
            state.currentIndex.value = index;
          },
          items: const [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.equalizer), label: '资产'),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
          ],
        ),
      ),
    );
  }
}
